import httpInstance from "@/utils/http";
import qs from "qs";

//获取所有的公告

export function getNoticeAllAPI(
  current: number,
  pageSize: number,
  query: string
) {
  return httpInstance({
    url: "/club/announcement/list/all",
    method: "POST",
    data: {
      current,
      pageSize,
      query,
    },
  });
}

// 删除公告（支持单个和批量删除）

export function deleteNoticeAPI(announcementIds: number | number[]) {
  const ids = Array.isArray(announcementIds)
    ? announcementIds
    : [announcementIds];

  return httpInstance({
    url: "/club/announcement/delete",
    method: "DELETE",
    params: {
      announcementIds: ids,
    },
    paramsSerializer: (params) => {
      return qs.stringify(params, { arrayFormat: "repeat" }); // announcementIds=1&announcementIds=2
    },
  });
}

//新增社团公告
export function addAnnouncementAPI(
  clubId: number,
  title: string,
  content: string
) {
  return httpInstance({
    url: "/club/announcement/add",
    method: "POST",
    data: {
      clubId,
      title,
      content,
    },
  });
}

//编辑社团公告
export function updateAnnouncementAPI(
  id:number,
  createTime:string,
  isDelete:number,
  clubId: number,
  title: string,
  content: string
) {
  return httpInstance({
    url: "/club/announcement/update",
    method: "POST",
    data: {
      clubId,
      title,
      content,
      id,
      isDelete,
      createTime,
    },
  });
}

